// pages/refundAudit/refundAudit.js
var $ = require('../util/commit.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    param:{},
    tarIndex: 0,//tarbar选择的index
    tabbar: [{
      id: 0,
      name: '待处理',
    }, {
      id: 1,
      name: '已退款'
    }, {
      id: 2,
      name: '已驳回'
    }],
    listData:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    let param=JSON.parse(options.data);
    that.setData({
      param,
    });
    that.loadData();
  },
// 加载事件
  loadData:function(e){
    let that =this;
    let tarIndex = that.data.tarIndex+1;
    $.POST({
      url:'caSCRA',
      data:{
        caid:that.data.param.id,
        status: tarIndex,
        page:1,
      }
    },function(e){
      that.setData({
        listData:e.data
      })
    },function(e){})
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // selectTarbar选择类别
  selectTarbar: function (e) {
    let index = e.currentTarget.dataset.index;
    let that = this;
    that.setData({
      tarIndex: index,
    });
    that.loadData();
  },
  // 跳转退款详情
  ToRefundADetail:function(e){
    $.openWin({
      url:'../refundAudit/refundADetail',
      data:{
        id: e.currentTarget.dataset.id,
        caid: e.currentTarget.dataset.caid
      }
    })
  },
  unAgree:function(e){
    let that=this;
    $.POST({
      url:'caCRA',
      data:{
        cuid:e.currentTarget.dataset.cuid,
        caid:that.data.param.id,
        status:2
      }
    },function(e){
      wx.showToast({
        title: e.msg,
        icon:'none'
      });
      that.loadData();
    },function(e){});
  },
  Agree: function (e) {
    let that = this;
    $.POST({
      url: 'caCRA',
      data: {
        cuid: e.currentTarget.dataset.cuid,
        caid: that.data.param.id,
        status: 1
      }
    }, function (e) {
      wx.showToast({
        title: e.msg,
        icon: 'none'
      });
      that.loadData();
    }, function (e) { });
  }
})